package com.controller;

import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.facade.UserFacade;
import com.model.User;

@SuppressWarnings("serial")
@ManagedBean
@SessionScoped
public class AdminController implements Serializable{
	
	@EJB
	private UserFacade userFacade;
	private List<User> listUsers;
	private int currentUserIndex;
	private User editedUser = new User();
	private User user;
	private int page = 1;
	
	public List<User> getListUsers() {
		listUsers = userFacade.showAllUsers();
		return listUsers;
	}
	
	public int getCurrentUserIndex() {
		return currentUserIndex;
	}


	public void setCurrentUserIndex(int currentUserIndex) {
		this.currentUserIndex = currentUserIndex;
	}


	public void remove(){
		userFacade.deleteUser(listUsers.get(currentUserIndex));		
	}
	
	public void update(){		
		userFacade.updateUser(editedUser);
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getEditedUser() {
		return editedUser;
	}

	public void setEditedUser(User editedUser) {
		this.editedUser = editedUser;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
	public void setEdited(){
		this.editedUser = listUsers.get(currentUserIndex);
	}
	
}
